package com.apes.fn.fico.expense;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.finance.model.IncomeType;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ExpenseItemDetailsBill.CONST_TABLE_NAME)
public class ExpenseItemDetailsBill extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_expense_item_details_bill";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "费用单明细细项单据序号")
    @Comment("序号")
    private String id;

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "statistic_date")
    @Comment("统计日期")
    private Date statisticDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "expense_item_details_id", referencedColumnName = "id")
    @Comment("平台费用明细细项号")
    private ExpenseItemDetails expenseItemDetails;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("公司编码")
    private PartyRole company;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("销售部门")
    private Dept dept;

    @Comment("单据")
    @Column(name = "order_id", length = 30)
    private String orderId;

    @Comment("单据类型")
    @Column(name = "order_type", length = 30)
    private String orderType;

    @Column(name = "source", length = 30)
    @Comment("源单据")
    private String source;

    @Column(name = "source_business_type", length = 32)
    @Comment("源单据类型")
    private String sourceBusinessType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "income_type", referencedColumnName = "id")
    @Comment("费用类型")
    private IncomeType incomeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "expense_details_type", referencedColumnName = "id")
    @Comment("费用细项")
    private Enumeration expenseDetailsType;

    @Column(name = "summary")
    @Comment("摘要")
    private String summary;

    @Column(name = "payment_amount", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("款项金额")
    private double paymentAmount = 0;

    @Column(name = "expense_amount", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("费用金额")
    private double expenseAmount = 0;

}



